package com.xudow.app.dynamicstate_old.module.follow.viewholder;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.xudow.app.R;
import com.xudow.app.dynamicstate_old.domain.entity.DynamicComment;
import com.xudow.app.dynamicstate_old.widget.UserClickableSpan;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ske on 2016/6/10.
 */
public class DynamicCommentViewHolder extends BaseViewHolder<DynamicComment> {
    @BindView(R.id.text_comment)
    TextView textComment;

    public DynamicCommentViewHolder(ViewGroup parent) {
        super(parent, R.layout.item_dynamic_comment);
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(DynamicComment data) {
        SpannableString spannableInfo;
        if (data.getpId() == 0) {
            spannableInfo = new SpannableString(data.getUserName() + " : " + data.getContent());
            spannableInfo.setSpan(new UserClickableSpan(getContext(), data.getUserProfileId()), 0, data.getUserName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            spannableInfo = new SpannableString(data.getUserName() + "回复" + data.getpName() + " : " + data.getContent());
            spannableInfo.setSpan(new UserClickableSpan(getContext(), data.getUserProfileId()), 0, data.getUserName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannableInfo.setSpan(new UserClickableSpan(getContext(), data.getpId()), data.getUserName().length() + 2, data.getUserName().length() + 2 + data.getpName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        textComment.setMovementMethod(LinkMovementMethod.getInstance());
//        textView.setPadding(0, JUtils.dip2px(2), 0, 0);
        textComment.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        textComment.setText(spannableInfo);
    }
}
